<Project>
  <PropertyGroup Condition="'$(TargetOS)' == 'browser'">
    <_TargetFrameworkForXHarness>$(AspNetCoreAppCurrent)</_TargetFrameworkForXHarness>
    <HelixTargetsFile>$(MSBuildThisFileDirectory)LocalEchoServer.helix.targets</HelixTargetsFile>

    <!-- handle different path to middleware in Helix -->
    <_TestEchoMiddleware Condition="'$(ContinuousIntegrationBuild)' == 'true' and '$(OS)' == 'Windows_NT'">%HELIX_CORRELATION_PAYLOAD%/xharness/TestEchoMiddleware</_TestEchoMiddleware>
    <_TestEchoMiddleware Condition="'$(ContinuousIntegrationBuild)' == 'true' and '$(OS)' != 'Windows_NT'">$HELIX_CORRELATION_PAYLOAD/xharness/TestEchoMiddleware</_TestEchoMiddleware>
    <_TestEchoMiddleware Condition="'$(ContinuousIntegrationBuild)' != 'true'">$(ArtifactsDir)bin/NetCoreServer/$(Configuration)/$(AspNetCoreAppCurrent)</_TestEchoMiddleware>

    <_RemoteLoopMiddleware Condition="'$(ContinuousIntegrationBuild)' == 'true' and '$(OS)' == 'Windows_NT'">%HELIX_CORRELATION_PAYLOAD%/xharness/RemoteLoopMiddleware</_RemoteLoopMiddleware>
    <_RemoteLoopMiddleware Condition="'$(ContinuousIntegrationBuild)' == 'true' and '$(OS)' != 'Windows_NT'">$HELIX_CORRELATION_PAYLOAD/xharness/RemoteLoopMiddleware</_RemoteLoopMiddleware>
    <_RemoteLoopMiddleware Condition="'$(ContinuousIntegrationBuild)' != 'true'">$(ArtifactsDir)bin/RemoteLoopServer/$(Configuration)/$(AspNetCoreAppCurrent)</_RemoteLoopMiddleware>

    <WasmXHarnessArgs>$(WasmXHarnessArgs) --web-server-use-cors --web-server-use-https</WasmXHarnessArgs>
    <WasmXHarnessArgs>$(WasmXHarnessArgs) --set-web-server-http-env=DOTNET_TEST_WEBSOCKETHOST,DOTNET_TEST_HTTPHOST,DOTNET_TEST_REMOTE_LOOP_HOST</WasmXHarnessArgs>
    <WasmXHarnessArgs>$(WasmXHarnessArgs) --set-web-server-https-env=DOTNET_TEST_SECUREWEBSOCKETHOST,DOTNET_TEST_SECUREHTTPHOST,DOTNET_TEST_HTTP2HOST</WasmXHarnessArgs>
    <WasmXHarnessArgs>$(WasmXHarnessArgs) --web-server-middleware=$(_RemoteLoopMiddleware)/RemoteLoopServer.dll,RemoteLoopServer.GenericHandler</WasmXHarnessArgs>
    <WasmXHarnessArgs>$(WasmXHarnessArgs) --web-server-middleware=$(_TestEchoMiddleware)/NetCoreServer.dll,NetCoreServer.GenericHandler</WasmXHarnessArgs>
  </PropertyGroup>

  <ItemGroup Condition="'$(TargetOS)' == 'browser'">
    <!-- The middleware doesn't need to be built for browser-wasm, so remove the relevant properties.
         Also, due to https://github.com/dotnet/runtime/issues/77707 RunAOTCompilation needs to be removed
         as a workaround. -->
    <ProjectReference
              Include="$(CommonTestPath)System/Net/Prerequisites/NetCoreServer/NetCoreServer.csproj"
              GlobalPropertiesToRemove="TargetOS;TargetArchitecture;RuntimeIdentifier;RunAOTCompilation"
              AdditionalProperties="_TargetFrameworkForXHarness=$(_TargetFrameworkForXHarness);NewtonsoftJsonVersion=$(NewtonsoftJsonVersion)"
              ReferenceOutputAssembly="false"/>
    <ProjectReference
              Include="$(CommonTestPath)System/Net/Prerequisites/RemoteLoopServer/RemoteLoopServer.csproj"
              GlobalPropertiesToRemove="TargetOS;TargetArchitecture;RuntimeIdentifier;RunAOTCompilation"
              AdditionalProperties="_TargetFrameworkForXHarness=$(_TargetFrameworkForXHarness)"
              ReferenceOutputAssembly="false"/>
    <Compile Include="$(CommonTestPath)System\Net\WebSockets\WebSocketStream.cs"
             Link="Common\System\Net\WebSockets\WebSocketStream.cs" />
  </ItemGroup>

  
  <!-- Tests use self-signed certificates that are refused by NodeJS -->
  <Target Name="AcceptUnauthorizedOnNodeJS" BeforeTargets="GenerateRunScript">
    <ItemGroup Condition="'$(OS)' != 'Windows_NT'">
      <SetScriptCommands Include="if [[ &quot;$SCENARIO&quot; == &quot;WasmTestOnNodeJS&quot; || &quot;$SCENARIO&quot; == &quot;wasmtestonnodejs&quot; ]]; then export NODE_TLS_REJECT_UNAUTHORIZED=0; fi" />
    </ItemGroup>
    <ItemGroup Condition="'$(OS)' == 'Windows_NT'">
      <SetScriptCommands Include="if /I [%SCENARIO%]==[WasmTestOnNodeJS] ( set &quot;NODE_TLS_REJECT_UNAUTHORIZED=0&quot; )" />
    </ItemGroup>
  </Target>
</Project>
